package com.taichuan.selfcheck.hardware;

import com.g3288.g3288board.Rk3399GpioActionDefine;
import com.g3288.g3288board.TcRk3399GpioClient;
import com.orhanobut.logger.Logger;
import com.taichuan.serialcommunication.SerialPortPublic;
import com.taichuan.tcutils.taichuan.SystemUtils;
import java.io.IOException;

/**
 * 该类主要用于
 *
 * @author CamelLuo
 * @version 2019/12/11
 */
public class DeviceUtils {
    private static final String TAG = DeviceUtils.class.getSimpleName();

    /**
     * 定义一个方法用于重启门口机
     */
    public static boolean rebootDevice() {
        SerialPortPublic.reboot();
        try {
            Runtime.getRuntime().exec("reboot");
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            Logger.t(TAG).e("执行重启异常： " + e.getMessage());
            return false;
        }
    }

    /**
     * 定义一个方法用于开启或关闭指纹模块的电控
     * @param isOpen
     */
    public static void openOrCloseFingerPrint(boolean isOpen){
        if (SystemUtils.isSupportZazFingerDevice()){
            if (SystemUtils.isRk3399()){
                if (isOpen) {
                    //开启指纹模块的电源供电
                    TcRk3399GpioClient.getInstance().controlGpio(Rk3399GpioActionDefine.CONTROL_FINGER_PRINT_OPEN);
                } else {
                    //关闭指纹模块的电源供电
                    TcRk3399GpioClient.getInstance().controlGpio(Rk3399GpioActionDefine.CONTROL_FINGER_PRINT_CLOSE);
                }
            }
        }
    }

    /**
     * 定义一个方法用于开启或关闭 TC-5000D-XL5(4G)设备 测温模块 的电控
     * @param isOpen
     */
    public static void openOrCloseXL5Temp(boolean isOpen){
        if (SystemUtils.isTC5000D_XL5_4G_WIFI_TempBoard()){
            if (SystemUtils.isRk3399()){
                if (isOpen) {
                    //开启指纹模块的电源供电
                    TcRk3399GpioClient.getInstance().controlGpio(Rk3399GpioActionDefine.CONTROL_ID_CARD_OR_TEMP_MODULE_OPEN);
                } else {
                    //关闭指纹模块的电源供电
                    TcRk3399GpioClient.getInstance().controlGpio(Rk3399GpioActionDefine.CONTROL_ID_CARD_OR_TEMP_MODULE_CLOSE);
                }
            }
        }
    }
}
